package com.coder520.common.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2017-7-9.
 */
public class DateUtils {

    private static Calendar calendar = Calendar.getInstance();
    /**
      *@Author Jay
      *@Date 2017-7-9 20:22
      *@Description  获取今天周几
      */
    public static int getTodayWeek() {

        calendar.setTime(new Date());
        int week = calendar.get(Calendar.DAY_OF_WEEK );
        int week2 = getWeek(week);
        return week2;
    }

    public static int getWeek(int week) { //查表法
        int[] arr = {0,7,1,2,3,4,5,6};
        return arr[week];
    }


    /**
      *@Author Jay
      *@Date 2017-7-9 20:22
      *@Description  计算时间差
      */
    public static int getMunite(Date startDate,Date endDate) {
        long start = startDate.getTime();
        long end = endDate.getTime();
        int hours = (int)(end - start)/60000;
        return hours;
    }

    /**
      *@Author Jay
      *@Date 2017-7-9 20:32
      *@Description    获取当天某个时间
      */
    public static Date getDate(int hour,int minute) {
        calendar.set(Calendar.HOUR_OF_DAY,hour);
        calendar.set(Calendar.MINUTE,minute);
        return calendar.getTime();
    }

}
